<template>
  <div class='home'>
    <!-- <van-empty style="padding: 0.01rem 0" description=""> </van-empty> -->

    <div
      class='bb'
      :style="{
        background:
          'url(' + baseImg + ') no-repeat 100%/100% rgba(0, 0, 0, 0.1)',
      }"
    ></div>
    <van-form v-if='notShow' style='padding-top: 20rem' @submit='onSubmit'>
      <van-cell-group inset>
        <van-field
          v-model='formData.queryCode'
          required
          maxlength='6'
          name='设定查询码'
          label='设定查询码：'
          placeholder='设定查询码'
          :rules="[{ required: true, message: '' }]"
        />
        <van-field
          v-model='formData.verifyQueryCode'
          required
          maxlength='6'
          name='确认查询码'
          label='确认查询码：'
          placeholder='确认查询码'
          :rules="[{ required: true, message: '' }]"
        />
      </van-cell-group>
      <div style='margin: 16px; margin-top: 2rem'>
        <van-button block type='info' native-type='submit'>提交</van-button>
        <div
          style='
            padding-top: 1rem;
            padding-left: 0.1rem;
            padding-right: 0.1rem;
          '
        >
          <div style=" padding-left: 30px; background: url('../../assets/images/record-gt.png');"></div>
          <!-- <img scr="../../assets/images/record-gt.png" style="width:4%"> -->
          <span style='font-size: 0.78rem; color: #ff6100'>
			  <img style='width: 4%' src='../../assets/images/record-gt.png' />
			  <b>&nbsp;请设定查询码并牢记，用于报备查询使用！</b>
		  </span>
        </div>
      </div>
    </van-form>
    <van-form v-else style='padding-top: 20rem' @submit='onSubmit'>
      <van-cell-group inset>
        <van-cell-group inset>
          <van-field
            v-model='formData.queryCode'
            center
            readonly
            clearable
            label='查询码'
          >
            <!-- <template #button>
            <van-button size="small" @click="shaxin()" type="primary"
              >刷新</van-button
            >
          </template> -->
          </van-field>
        </van-cell-group>
      </van-cell-group>
      <div style='padding-top: 1rem; padding-left: 2.24rem'>
        <img style='width: 4%' src='../../assets/images/record-gt.png' />
        <span style='font-size: 0.78rem; color: #ff6100'>
				<b>&nbsp;请牢记查询码，建议截图保存！</b>
			</span>
      </div>
    </van-form>
  </div>
</template>

<script>
import area from '@/libs/area.json'
import {
  getQrUrl,
  editQueryCode,
  editReloadQueryCode
} from '@/api/self/help'
import { Toast, Dialog } from 'vant'

export default {
  data () {
    return {
      baseImg: '',
      notShow: true,
      formData: {
        queryCode: '',
        verifyQueryCode: '',
        certificatesNo: ''
      },
      queryObj: {
        certificatesNo: '',
        queryCode: ''
      }
    }
  },
  created () {
    let queryCode = this.$route.query.queryCode
    this.queryObj.queryCode = queryCode
    this.queryObj.certificatesNo = this.$route.query.certificatesNo
    console.log('1231231', this.queryObj)
    getQrUrl(this.queryObj).then((res) => {
      if (res.data.errcode === 0) {
        this.baseImg = res.data.data.qrUrl
        if (queryCode == null || queryCode === '') {
          this.notShow = true
        } else {
          this.formData.queryCode = queryCode
          this.notShow = false
        }
      }
    })
  },
  methods: {
    shaxin () {
      let data = {
        certificatesNo: this.$route.query.certificatesNo,
        queryCode: this.formData.queryCode
      }
      editReloadQueryCode(data).then((res) => {
        if (res.data.errcode === 0) {
          this.formData.queryCode = res.data.data.queryCode
          this.baseImg = res.data.data.qrUrl
        } else {
          Toast.fail(res.data.errmsg)
        }
      })
    },
    goToRest () {
      this.$router.push({
        name: 'record',
        query: { id: this.$route.query.id, code: this.$route.query.code }
      })
    },
    onSubmit () {
      var reg = /^[0-9a-zA-Z]{6}$/
      console.log(reg.test(this.formData.queryCode))
      if (
        !reg.test(this.formData.queryCode) &&
        !reg.test(this.formData.verifyQueryCode)
      ) {
        Toast.fail('查询码为6为英文或数字')
        return
      }

      if (this.formData.queryCode != this.formData.verifyQueryCode) {
        Toast.fail('查询码请确认一致')
      } else {
        let data = {
          queryCode: this.formData.queryCode,
          verifyQueryCode: this.formData.verifyQueryCode,
          certificatesNo: this.$route.query.certificatesNo
        }
        editQueryCode(data).then((res) => {
          Toast.clear()
          if (res.data.errcode === 0) {
            this.baseImg = res.data.data.qrUrl
            this.notShow = false
          } else {
            Toast.fail(res.data.errmsg)
          }
        })
      }
    }
  }
}
</script>
<style lang='less' scoped>
.bb,
.bb::before,
.bb::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.bb {
  width: 450px;
  height: 450px;
  margin: 200px auto 6px auto;

  /* background: url(baseImg) no-repeat 50%/70% rgba(0, 0, 0, 0.1); */
  color: #cac662;
  // box-shadow: inset 0 0 0 1px rgba(105, 202, 98, 0.5);
}

.bb::before,
.bb::after {
  content: '';
  z-index: 2;
  margin: -5%;
  box-shadow: inset 0 0 0 7px;
  animation: clipMe 8s linear infinite;
}

.bb::before {
  animation-delay: -4s;
}

.bb:hover::after,
.bb:hover::before {
  // background-color: rgba(255, 0, 0, 0.3);
}

@keyframes clipMe {
  0%,
  100% {
    clip: rect(0px, 520px, 2px, 0px);
  }
  25% {
    clip: rect(0px, 2px, 520px, 0px);
  }
  50% {
    clip: rect(518px, 520px, 520px, 0px);
  }
  75% {
    clip: rect(0px, 5100px, 520px, 500px);
  }
}
</style>
<style lang='less' scoped>
.upload-img-5 {
  margin: 5px 0 90px 0;
}

.upload-img-1 {
  margin: 5px 0 15px 0;
}

.home {
  //   background: url('../../assets/images/smtb.jpg')no-repeat;
  background: url('../../assets/images/record-info.png') no-repeat;
  background-size: cover;
  min-height: 100vh;
  justify-content: center;
  align-items: center;
  height: 100%;

  img {
    width: 100%;
  }

  .dialog-container {
    height: 70vh;
    overflow-y: auto;
  }

  .get-area {
    width: 100%;
    padding: 0 0.8rem;
    font-size: 0.747rem;
    color: #fff;
    background-color: #1989fa;
    border: 0.053rem solid #1989fa;
    height: 2.347rem;
    line-height: 2.347rem;
    text-align: center;
    border-radius: 0.107rem;
    cursor: pointer;
    box-sizing: border-box;
    margin-right: 10px;
  }

  /deep/ .van-field__label {
    width: 8em;
  }

  /deep/ .van-field__error-message {
    text-align: right;
  }

  .title {
    // font-size: 28px;
    text-indent: 20px;
    padding: 50px 0 20px;
  }

  .container {
    width: 90%;
    height: 80vh;
    overflow-y: auto;
    border: 1px solid #adadad;
    margin: auto;

    .item {
      margin: 10px;
    }
  }
}

.up-and-down {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f1f3f4;
  height: 80px;
  color: #333;
}

// .home .blue {
//   background-color: transparent;
// }
// .home .van-cell{
//  background-color: transparent;
// }
</style>
